package leetcode.editor.cn.q1xx

import leetcode.editor.cn.TreeNode
import kotlin.math.min

class Q111 {
    fun minDepth(root: TreeNode?): Int {
        if (root==null) return 0
        if (root.left == null && root.right == null) return 1
        var minDepth = Int.MAX_VALUE
        if (root.left != null) {
            minDepth = min(minDepth(root.left), minDepth)
        }
        if (root.right != null) {
            minDepth = min(minDepth(root.right), minDepth)
        }
        return minDepth + 1
    }
}